<template>
  <a-spin :spinning="confirmLoading">
    <B>企业名称： {{qyzhm}}</B><B style="margin-left: 20px;">结算单号：{{jsdh}}</B><B style="margin-left: 20px;">结算状态：待结算</B>
    <a-page-header style="border: 1px solid;" title="收款人信息列表">
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :pagination="false"
        :columns="columns"
        :dataSource="dataSource"
        class="j-table-force-nowrap">
      </a-table>
    </a-page-header>
    <a-page-header style="border: 1px solid; margin-top: 10px; " title="项目基本信息">
      <a-card :bordered="false" style="background-color: #fff;">
        <a-descriptions size="small" :column="4">
          <a-descriptions-item label="发起时间"> {{fbsj}} </a-descriptions-item>
          <a-descriptions-item label="项目编号"> {{xmbh}} </a-descriptions-item>
          <a-descriptions-item label="工作城市"> {{gzcsmc}} </a-descriptions-item>
          <a-descriptions-item label="任务总金额">{{rwzje}} </a-descriptions-item>
          <a-descriptions-item label="项目名称">{{xmmc}} </a-descriptions-item>
          <a-descriptions-item label="年龄要求">{{nlyq}}</a-descriptions-item>
          <a-descriptions-item label="学历要求">{{xlyq}}</a-descriptions-item>
          <a-descriptions-item label="经验要求">{{jyyq}}</a-descriptions-item>
          <a-descriptions-item label="项目类型">{{xmlx}} </a-descriptions-item>
          <a-descriptions-item label="需要人数">{{xyrs}} </a-descriptions-item>
          <a-descriptions-item label="项目协议编号"> {{xmxybh}}</a-descriptions-item>
        </a-descriptions>
        <a-descriptions size="small" :column="2">
          <a-descriptions-item label="项目起止时间">{{xmqrq}} -- {{xmzrq}} </a-descriptions-item>
          <a-descriptions-item label="工作时间">{{gzkssj}} -- {{gzjssj}} </a-descriptions-item>
        </a-descriptions>
        <a-descriptions size="small" :column="1">
          <a-descriptions-item label="项目内容"> {{xmnr}} </a-descriptions-item>
        </a-descriptions>
        <a-descriptions size="small" :column="1">
          <a-descriptions-item label="验收标准"> {{ysbz}} </a-descriptions-item>
        </a-descriptions>
      </a-card>
    </a-page-header>
  </a-spin>
</template>

<script>

  import { postAction, getAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  import JFormContainer from '@/components/jeecg/JFormContainer'

  export default {
    name: 'PtDjsForm',
    components: {
      JFormContainer,
    },
    props: {
      //流程表单data
      formData: {
        type: Object,
        default: ()=>{},
        required: false
      },
      //表单模式：true流程表单 false普通表单
      formBpm: {
        type: Boolean,
        default: false,
        required: false
      },
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        form: this.$form.createForm(this),
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/project/lhygQyFinance/add",
          edit: "/project/lhygQyFinance/edit",
          queryById: "/project/lhygQyFinance/queryById",
          getSkrList: "/project/lhygQyFinance/getSkrDjsList",
          getXmInfo: "/project/lhygQyFinance/getXmInfo",
        },
        dataSource: [],
        columns: [
          {
            title:'姓名',
            align:"center",
            dataIndex: 'name',
          },
          {
            title:'身份证号',
            align:"center",
            dataIndex: 'identityid',
          },
          {
            title:'手机号',
            align:"center",
            dataIndex: 'phone',
          },
          // {
          //   title:'任务金额（元）',
          //   align:"center",
          //   dataIndex: 'rwje',
          // },
          {
            title:'结算金额（元）',
            align:"center",
            dataIndex: 'fkje',
          },
          {
            title:'本次纳税金额',
            align:"center",
            dataIndex: 'taxje',
          },
          {
            title:'验收单号',
            align:"center",
            dataIndex: 'ysdh',
          },
          {
            title:'备注',
            align:"center",
            dataIndex: 'bz',
          },
        ],
        qyzhm: '',
        jsdh: '',
        fbsj: '',
        xmbh: '',
        xmxybh: '',
        gzcsmc: '',
        xmmc: '',
        xmlx: '',
        xyrs: '',
        rwzje: '',
        nlyq: '',
        xlyq: '',
        jyyq: '',
        xmqrq: '',
        xmzrq: '',
        gzkssj: '',
        gzjssj: '',
        xmnr: '',
        ysbz: '',
      }
    },
    computed: {
      formDisabled(){
        if(this.formBpm===true){
          if(this.formData.disabled===false){
            return false
          }
          return true
        }
        return this.disabled
      },
      showFlowSubmitButton(){
        if(this.formBpm===true){
          if(this.formData.disabled===false){
            return true
          }
        }
        return false
      }
    },
    created () {
      //如果是流程中表单，则需要加载流程表单data
      this.showFlowData();
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        const that = this;
        that.getSkrList(record.ids, record.xmlxid);
        that.qyzhm = record.qyzhm;
        that.jsdh = record.jsdh;
          let formData=new FormData();
          formData.append('xmbh', record.xmbh);
          postAction(that.url.getXmInfo, formData).then(res => {
              if (res.success) {
                  that.fbsj = res.result.records[0].fbsj;
                  that.xmbh = res.result.records[0].xmbh;
                  that.xmxybh = res.result.records[0].xmxybh;
                  that.gzcsmc = res.result.records[0].gzcsmc;
                  that.xmmc = res.result.records[0].xmmc;
                  that.xmlx = res.result.records[0].xmlx;
                  that.xyrs = res.result.records[0].xyrs;
                  that.rwzje = res.result.records[0].rwzje;
                  that.nlyq = res.result.records[0].nlyq_dictText;
                  that.xlyq = res.result.records[0].xlyq_dictText;
                  that.jyyq = res.result.records[0].jyyq_dictText;
                  that.xmqrq = res.result.records[0].xmqrq;
                  that.xmzrq = res.result.records[0].xmzrq;
                  that.gzkssj = res.result.records[0].gzkssj;
                  that.gzjssj = res.result.records[0].gzjssj;
                  that.xmnr = res.result.records[0].xmnr;
                  that.ysbz = res.result.records[0].ysbz;
              } else {
                  that.$message.warning(res.message);
              }
          })
      },
      //渲染流程表单数据
      showFlowData(){
        if(this.formBpm === true){
          let params = {id:this.formData.dataId};
          getAction(this.url.queryById,params).then((res)=>{
            if(res.success){
              this.edit (res.result);
            }
          });
        }
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }

        })
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'jsdh','fwfl','jsje','fwfje','zje','name','ywckh','fkpz','ids','qykh','qykhh','ptkh','ptkhh','ptzhm'))
      },
      getSkrList(ids, xmlxid){
        let skrThis = this;
        let formData=new FormData();
        formData.append('ids', ids);
        formData.append('xmlxid', xmlxid);
        postAction(skrThis.url.getSkrList, formData).then(res => {
          if (res.success) {
              skrThis.dataSource = res.result;
          } else {
              skrThis.$message.warning(res.message);
          }
        })
      },
    }
  }
</script>